from PyQt5.QtWidgets import QApplication, QMenu, QAction, QFrame, QLabel
from PyQt5.QtGui import QIcon
from app_setup import InitWindow

import sys


class MenuBarWindow(InitWindow):
    def __init__(self):
        super(MenuBarWindow, self).__init__()

        self.menuBars = self.menuBar()
        self.menuBars.setObjectName('MenuBar')

        self.menuFile = QMenu(self.menuBars)
        self.menuFile.setObjectName('menuFile')
        self.menuFile.setTitle('&工程(P)')

        self.menuImage = QMenu(self.menuBars)
        self.menuImage.setObjectName('menuImage')
        self.menuImage.setTitle('&图像(V)')

        self.menuLabel = QMenu(self.menuBars)
        self.menuLabel.setObjectName('menuLabel')
        self.menuLabel.setTitle('&标签(L)')

        self.menuSplit = QMenu(self.menuBars)
        self.menuSplit.setObjectName('menuSplit')
        self.menuSplit.setTitle('&分割(K)')

        self.menuOut = QMenu(self.menuBars)
        self.menuOut.setObjectName('menuOut')
        self.menuOut.setTitle('&输出(T)')

        self.menuBar().addMenu(self.menuFile)
        self.menuBar().addMenu(self.menuImage)
        self.menuBar().addMenu(self.menuLabel)
        self.menuBar().addMenu(self.menuSplit)
        self.menuBar().addMenu(self.menuOut)
        # ----- 菜单栏设置 ----- #

        self.actionFileCreateProject = QAction(QIcon('static/imgs/xinjiangongcheng.png'), '&新建(Ctrl+N)', self.menuFile)
        self.actionFileCreateProject.setObjectName('CreateProject')
        self.actionFileCreateProject.setShortcut('Ctrl+N')

        self.actionFileOpenProject = QAction(QIcon('static/imgs/dakaigongcheng.png'), '&打开(Ctrl+O)', self.menuFile)
        self.actionFileOpenProject.setObjectName('OpenProject')
        self.actionFileOpenProject.setShortcut('Ctrl+O')

        self.actionSaveProject = QAction(QIcon('static/imgs/baocungongcheng.png'), '&保存(Ctrl+S)', self.menuFile)
        self.actionSaveProject.setObjectName('SaveProject')
        self.actionSaveProject.setShortcut('Ctrl+S')

        self.actionSaveNowProject = QAction('&另存为(P)...', self.menuFile)
        self.actionSaveNowProject.setObjectName('SaveNowProject')
        self.actionSaveNowProject.setShortcut('Ctrl+P')

        self.actionExit = QAction('&退出(Ctrl+Q)', self.menuFile)
        self.actionExit.setObjectName('Exit')
        self.actionExit.setShortcut('Ctrl+Q')

        self.menuFile.addActions(
            [self.actionFileCreateProject, self.actionFileOpenProject, self.menuFile.addSeparator(),
             self.actionSaveProject, self.actionSaveNowProject, self.menuFile.addSeparator(),
             self.menuFile.addSeparator(), self.actionExit])
        # ----- 菜单栏的工程设置 ----- #

        self.actionNextPage = QAction(QIcon('static/imgs/xiayizhangtupian.png'), '&下一张(Alt+N)', self.menuImage)
        self.actionNextPage.setObjectName('NextPage')
        self.actionNextPage.setShortcut('Alt+N')

        self.actionLastPage = QAction(QIcon('static/imgs/shangyizhangtupian.png'), '&上一张(Alt+B)', self.menuImage)
        self.actionLastPage.setObjectName('LastPage')
        self.actionLastPage.setShortcut('Alt+B')

        self.actionDeletePage = QAction(QIcon('static/imgs/shanchutuxiang.png'), '&删除(Alt+D)', self.menuImage)
        self.actionDeletePage.setObjectName('DeletePage')
        self.actionDeletePage.setShortcut('Alt+D')

        self.actionAddPage = QAction(QIcon('static/imgs/tianjiatuxiang.png'), '&添加图片(Alt+A)', self.menuImage)
        self.actionAddPage.setObjectName('AddPage')
        self.actionAddPage.setShortcut('Alt+A')

        self.menuImage.addActions(
            [self.actionNextPage, self.actionLastPage, self.actionDeletePage, self.menuImage.addSeparator(),
             self.actionAddPage])
        # ----- 菜单栏的图片设置 ----- #

        self.actionNewLabel = QAction(QIcon('static/imgs/tianjia.png'), '&新建标签(Shift+N)', self.menuLabel)
        self.actionNewLabel.setObjectName('NewLabel')
        self.actionNewLabel.setShortcut('Shift+N')

        self.actionEditLabel = QAction(QIcon('static/imgs/bianji.png'), '&编辑标签(Shift+E)', self.menuLabel)
        self.actionEditLabel.setObjectName('EditLabel')
        self.actionEditLabel.setShortcut('Shift+E')

        self.actionDeleteLabel = QAction(QIcon('static/imgs/biaoqianshanchu.png'), '&删除标签(Shift+D)', self.menuLabel)
        self.actionDeleteLabel.setObjectName('DeleteLabel')
        self.actionDeleteLabel.setShortcut('Shift+D')

        self.menuLabel.addActions([self.actionNewLabel, self.actionEditLabel, self.actionDeleteLabel])
        # ----- 菜单栏的标签设置 ----- #

        self.actionUndoPixel = QAction(QIcon('static/imgs/chexiao.png'), '&撤销点(Ctrl+Z)', self.menuSplit)
        self.actionUndoPixel.setObjectName('UndoPixel')

        self.actionUndoPixel.setShortcut('Ctrl+Z')

        self.actionRedoPixel = QAction(QIcon('static/imgs/zhongzuo.png'), '&重做点(Ctrl+Y)', self.menuSplit)
        self.actionRedoPixel.setObjectName('RedoPixel')

        self.actionRedoPixel.setShortcut('Ctrl+Y')

        self.actionRefreshPixel = QAction(QIcon('static/imgs/qingkong.png'), '&清空点(Ctrl+U)', self.menuSplit)
        self.actionRefreshPixel.setObjectName('RefreshPixel')

        self.actionRefreshPixel.setShortcut('Ctrl+U')

        self.menuSplit.addActions([self.actionUndoPixel, self.actionRedoPixel, self.actionRefreshPixel])
        # ----- 菜单栏的点位设置 ----- #

        self.actionMutiRename = QAction('&批量改名(F1)', self.menuOut)
        self.actionMutiRename.setObjectName('MutiRename')
        self.actionMutiRename.setShortcut('F1')

        self.actionChangeFileSpace = QAction('&更改输出文件夹(F2)', self.menuOut)
        self.actionChangeFileSpace.setObjectName('ChangeFileSpace')
        self.actionChangeFileSpace.setShortcut('F2')

        self.actionOutDelete = QAction(QIcon('static/imgs/shanchuyitiaoxuanxiang.png'), '&删除一条记录(F3)', self.menuOut)
        self.actionOutDelete.setObjectName('OutDelete')
        self.actionOutDelete.setShortcut('F3')

        self.actionOutDeleteAll = QAction('&清空所有记录(F4)', self.menuOut)
        self.actionOutDeleteAll.setObjectName('OutDeleteAll')
        self.actionOutDeleteAll.setShortcut('F4')

        self.actionOut = QAction(QIcon('static/imgs/shuchu.png'), '&输出数据集(F5)', self.menuOut)
        self.actionOut.setObjectName('Out')
        self.actionOut.setShortcut('F5')

        self.menuOut.addActions([self.actionMutiRename, self.menuOut.addSeparator(), self.actionChangeFileSpace,
                                 self.menuOut.addSeparator(), self.actionOutDelete, self.actionOutDeleteAll,
                                 self.menuOut.addSeparator(), self.actionOut])
        # ----- 菜单栏的输出设置 ----- #

        self.actionSaveProject.setEnabled(False)
        self.actionSaveNowProject.setEnabled(False)

        self.actionNextPage.setEnabled(False)
        self.actionLastPage.setEnabled(False)
        self.actionDeletePage.setEnabled(False)
        self.actionAddPage.setEnabled(False)

        self.actionNewLabel.setEnabled(False)
        self.actionEditLabel.setEnabled(False)
        self.actionDeleteLabel.setEnabled(False)

        self.actionRedoPixel.setEnabled(False)
        self.actionUndoPixel.setEnabled(False)
        self.actionRefreshPixel.setEnabled(False)

        self.actionMutiRename.setEnabled(False)
        self.actionOutDelete.setEnabled(False)
        self.actionOutDeleteAll.setEnabled(False)
        self.actionOut.setEnabled(False)
        # ----- 初始状态Action设置 ----- #
        self.supportImageTuple = ('.bmp', '.jpeg', '.jpg', '.jpe',
                                  '.png', '.pbm', '.pgm', '.ppm',
                                  '.sr', '.ras', '.tiff', '.tif',
                                  '.exr', '.jp2')

        self.statusBars = self.statusBar()

        Vline = QFrame()
        Vline.setFrameShape(QFrame.VLine | QFrame.Sunken)

        self.imageStatusLabel = QLabel('(Name：XXX, Size：XXX)')
        self.imageInfoLabel = QLabel('(W:XXX,H:XXX Scale:XX%)')
        self.mouseAndColorPointLabel = QLabel('[Clicked(XXX,XXX) RGB(XXX,XXX,XXX)]')

        self.statusBars.showMessage('装备就绪!')
        self.statusBars.addPermanentWidget(Vline)
        self.statusBars.addPermanentWidget(self.imageStatusLabel)
        self.statusBars.addPermanentWidget(Vline)
        self.statusBars.addPermanentWidget(self.imageInfoLabel)
        self.statusBars.addPermanentWidget(Vline)
        self.statusBars.addPermanentWidget(self.mouseAndColorPointLabel)

        self.projectCreatedSignal = False # 工程激活状态位
        self.projectFileContent = []  # 工程内容JSon对象
        self.globalWorkPath = '' # 工程路径
        self.globalWorkPathFile = '' # 工程文件路径
        self.globalImageBox = None # 全局图像盒子
        self.globalImageDics = {}  # 全局图像标签字典
        # ----- 状态，变量初始化设置 ----- #


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_window = MenuBarWindow()
    main_window.windowShow()
    sys.exit(app.exec_())
